package com.lbd.system.controller;

import com.lbd.base.controller.BaseController;
import com.lbd.commons.Result;
import com.lbd.commons.ResultState;
import com.lbd.system.bean.UserRole;
import com.lbd.system.service.UserRoleService;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by WangYajie on 2016/9/19.
 */
@RestController
@RequestMapping("/userRole")
public class UserRoleController extends BaseController {
    private Logger log = Logger.getLogger(this.getClass());
    @Autowired
    UserRoleService userRoleService;

    /**
     * 给用户授权
     *
     * @param ids
     * @param uid
     * @return
     */
    @RequestMapping(value = "/assign", method = RequestMethod.POST)
    public Result assign(@RequestParam(required = false, name = "rids[]") String[] ids, @RequestParam("uid") String uid) {
        userRoleService.assign(uid, ids);
        return new Result(ResultState.SUCCESS, "授权成功", "");
    }

    @RequestMapping(value = "/listByUserId")
    public Result listByRole(String id) {
        List<UserRole> list = userRoleService.findByEmpId(id);
        return new Result(ResultState.SUCCESS, "成功", list);
    }


}
